{
 "metadata": {
  "name": "",
  "signature": "sha256:7399202906f87b6e0623329d6f5ceea4fcfb165c666825dc6412c947e4a083a5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "import pandas as pd\n",
      "import matplotlib.pyplot as plt\n",
      "import seaborn as sns\n",
      "plt.style.use('fivethirtyeight')\n",
      "import warnings\n",
      "warnings.filterwarnings('ignore')\n",
      "%matplotlib inline"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data = pd.read_csv(\"train.csv\")\n",
      "data.head()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>PassengerId</th>\n",
        "      <th>Survived</th>\n",
        "      <th>Pclass</th>\n",
        "      <th>Name</th>\n",
        "      <th>Sex</th>\n",
        "      <th>Age</th>\n",
        "      <th>SibSp</th>\n",
        "      <th>Parch</th>\n",
        "      <th>Ticket</th>\n",
        "      <th>Fare</th>\n",
        "      <th>Cabin</th>\n",
        "      <th>Embarked</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>3</td>\n",
        "      <td>Braund, Mr. Owen Harris</td>\n",
        "      <td>male</td>\n",
        "      <td>22.0</td>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>A/5 21171</td>\n",
        "      <td>7.2500</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>2</td>\n",
        "      <td>1</td>\n",
        "      <td>1</td>\n",
        "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
        "      <td>female</td>\n",
        "      <td>38.0</td>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>PC 17599</td>\n",
        "      <td>71.2833</td>\n",
        "      <td>C85</td>\n",
        "      <td>C</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td>3</td>\n",
        "      <td>1</td>\n",
        "      <td>3</td>\n",
        "      <td>Heikkinen, Miss. Laina</td>\n",
        "      <td>female</td>\n",
        "      <td>26.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>STON/O2. 3101282</td>\n",
        "      <td>7.9250</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td>4</td>\n",
        "      <td>1</td>\n",
        "      <td>1</td>\n",
        "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
        "      <td>female</td>\n",
        "      <td>35.0</td>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>113803</td>\n",
        "      <td>53.1000</td>\n",
        "      <td>C123</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td>5</td>\n",
        "      <td>0</td>\n",
        "      <td>3</td>\n",
        "      <td>Allen, Mr. William Henry</td>\n",
        "      <td>male</td>\n",
        "      <td>35.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>373450</td>\n",
        "      <td>8.0500</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 23,
       "text": [
        "   PassengerId  Survived  Pclass  \\\n",
        "0            1         0       3   \n",
        "1            2         1       1   \n",
        "2            3         1       3   \n",
        "3            4         1       1   \n",
        "4            5         0       3   \n",
        "\n",
        "                                                Name     Sex   Age  SibSp  \\\n",
        "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
        "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
        "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
        "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
        "4                           Allen, Mr. William Henry    male  35.0      0   \n",
        "\n",
        "   Parch            Ticket     Fare Cabin Embarked  \n",
        "0      0         A/5 21171   7.2500   NaN        S  \n",
        "1      0          PC 17599  71.2833   C85        C  \n",
        "2      0  STON/O2. 3101282   7.9250   NaN        S  \n",
        "3      0            113803  53.1000  C123        S  \n",
        "4      0            373450   8.0500   NaN        S  "
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.describe()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>PassengerId</th>\n",
        "      <th>Survived</th>\n",
        "      <th>Pclass</th>\n",
        "      <th>Age</th>\n",
        "      <th>SibSp</th>\n",
        "      <th>Parch</th>\n",
        "      <th>Fare</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>count</th>\n",
        "      <td>891.000000</td>\n",
        "      <td>891.000000</td>\n",
        "      <td>891.000000</td>\n",
        "      <td>714.000000</td>\n",
        "      <td>891.000000</td>\n",
        "      <td>891.000000</td>\n",
        "      <td>891.000000</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mean</th>\n",
        "      <td>446.000000</td>\n",
        "      <td>0.383838</td>\n",
        "      <td>2.308642</td>\n",
        "      <td>29.699118</td>\n",
        "      <td>0.523008</td>\n",
        "      <td>0.381594</td>\n",
        "      <td>32.204208</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>std</th>\n",
        "      <td>257.353842</td>\n",
        "      <td>0.486592</td>\n",
        "      <td>0.836071</td>\n",
        "      <td>14.526497</td>\n",
        "      <td>1.102743</td>\n",
        "      <td>0.806057</td>\n",
        "      <td>49.693429</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>min</th>\n",
        "      <td>1.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>1.000000</td>\n",
        "      <td>0.420000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>0.000000</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>25%</th>\n",
        "      <td>223.500000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>2.000000</td>\n",
        "      <td>20.125000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>7.910400</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>50%</th>\n",
        "      <td>446.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>3.000000</td>\n",
        "      <td>28.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>14.454200</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>75%</th>\n",
        "      <td>668.500000</td>\n",
        "      <td>1.000000</td>\n",
        "      <td>3.000000</td>\n",
        "      <td>38.000000</td>\n",
        "      <td>1.000000</td>\n",
        "      <td>0.000000</td>\n",
        "      <td>31.000000</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>max</th>\n",
        "      <td>891.000000</td>\n",
        "      <td>1.000000</td>\n",
        "      <td>3.000000</td>\n",
        "      <td>80.000000</td>\n",
        "      <td>8.000000</td>\n",
        "      <td>6.000000</td>\n",
        "      <td>512.329200</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 54,
       "text": [
        "       PassengerId    Survived      Pclass         Age       SibSp  \\\n",
        "count   891.000000  891.000000  891.000000  714.000000  891.000000   \n",
        "mean    446.000000    0.383838    2.308642   29.699118    0.523008   \n",
        "std     257.353842    0.486592    0.836071   14.526497    1.102743   \n",
        "min       1.000000    0.000000    1.000000    0.420000    0.000000   \n",
        "25%     223.500000    0.000000    2.000000   20.125000    0.000000   \n",
        "50%     446.000000    0.000000    3.000000   28.000000    0.000000   \n",
        "75%     668.500000    1.000000    3.000000   38.000000    1.000000   \n",
        "max     891.000000    1.000000    3.000000   80.000000    8.000000   \n",
        "\n",
        "            Parch        Fare  \n",
        "count  891.000000  891.000000  \n",
        "mean     0.381594   32.204208  \n",
        "std      0.806057   49.693429  \n",
        "min      0.000000    0.000000  \n",
        "25%      0.000000    7.910400  \n",
        "50%      0.000000   14.454200  \n",
        "75%      0.000000   31.000000  \n",
        "max      6.000000  512.329200  "
       ]
      }
     ],
     "prompt_number": 54
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.loc[data['Sex']=='male', 'Sex']=1\n",
      "data.loc[data['Sex']=='female', 'Sex']=0"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 62
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data['Age'].mean()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 64,
       "text": [
        "29.69911764705882"
       ]
      }
     ],
     "prompt_number": 64
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.loc[data['Age'].isnull(), 'Age']=29.69911"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 68
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.isnull().sum()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 69,
       "text": [
        "PassengerId      0\n",
        "Survived         0\n",
        "Pclass           0\n",
        "Name             0\n",
        "Sex              0\n",
        "Age              0\n",
        "SibSp            0\n",
        "Parch            0\n",
        "Ticket           0\n",
        "Fare             0\n",
        "Cabin          687\n",
        "Embarked         2\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 69
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = []\n",
      "y = []\n",
      "len1 = data.shape[0]\n",
      "#sample = data.iloc[0, [2,4,5,6,7,9]]\n",
      "#np.array(sample)\n",
      "for i in range(len1):\n",
      "    sample = data.iloc[i, [2,4,5,6,7,9]]\n",
      "    x.append(np.array(sample))\n",
      "    y.append(data.iat[i,1])\n",
      "x = np.array(x)\n",
      "y = np.array(y)\n",
      "print (x)\n",
      "print (y)\n",
      "print (len(x))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[[3 1 22.0 1 0 7.25]\n",
        " [1 0 38.0 1 0 71.283299999999997]\n",
        " [3 0 26.0 0 0 7.9249999999999998]\n",
        " ..., \n",
        " [3 0 29.699110000000001 1 2 23.449999999999999]\n",
        " [1 1 26.0 0 0 30.0]\n",
        " [3 1 32.0 0 0 7.75]]\n",
        "[0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 0 1\n",
        " 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 0\n",
        " 1 0 0 0 1 1 0 1 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 0\n",
        " 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0\n",
        " 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1\n",
        " 0 1 1 0 0 1 0 1 1 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 1 0 1 0 0 0 1 1 0 1 0 1 0\n",
        " 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 1\n",
        " 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0\n",
        " 0 0 1 1 1 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 0 1 0 1 1 1 1 0 0\n",
        " 0 1 0 0 1 1 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 1\n",
        " 1 0 0 0 0 1 1 0 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0\n",
        " 1 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 1 0 1 0 0 1 0 0 1\n",
        " 1 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0\n",
        " 0 0 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0\n",
        " 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1\n",
        " 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 1 0 0 0 1\n",
        " 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 0\n",
        " 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 0\n",
        " 0 0 0 1 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 0 1 1 0\n",
        " 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 0\n",
        " 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0\n",
        " 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 1 0 0 0 0\n",
        " 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 0\n",
        " 0 0 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1\n",
        " 0 1 0]\n",
        "891\n"
       ]
      }
     ],
     "prompt_number": 83
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sklearn.model_selection import train_test_split\n",
      "\n",
      "x_train, x_test, y_train, y_test = train_test_split(\n",
      "    x, y, test_size=0.1, shuffle=False)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 88
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "y_train"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 89,
       "text": [
        "array([0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1,\n",
        "       1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0,\n",
        "       0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1,\n",
        "       0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0,\n",
        "       0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0,\n",
        "       0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0,\n",
        "       0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,\n",
        "       1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,\n",
        "       1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,\n",
        "       1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0,\n",
        "       1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,\n",
        "       0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1,\n",
        "       0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1,\n",
        "       1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0,\n",
        "       1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0,\n",
        "       1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,\n",
        "       1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1,\n",
        "       1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,\n",
        "       1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0,\n",
        "       1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0,\n",
        "       1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,\n",
        "       1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,\n",
        "       1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,\n",
        "       0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0,\n",
        "       0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0,\n",
        "       0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,\n",
        "       0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,\n",
        "       1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1,\n",
        "       1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,\n",
        "       0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,\n",
        "       1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1,\n",
        "       0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0,\n",
        "       0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0,\n",
        "       1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1,\n",
        "       0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0])"
       ]
      }
     ],
     "prompt_number": 89
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sklearn.ensemble import RandomForestClassifier\n",
      "from sklearn.ensemble import AdaBoostClassifier\n",
      "from sklearn.ensemble import GradientBoostingClassifier\n",
      "import lightgbm as lgb\n",
      "from xgboost import XGBClassifier\n",
      "import time\n",
      "\n",
      "rf = RandomForestClassifier()\n",
      "ada = AdaBoostClassifier()\n",
      "gbdt = GradientBoostingClassifier()\n",
      "lgb = lgb.LGBMClassifier(num_leaves=127, n_estimators=200, max_depth=6, learning_rate=0.3, reg_alpha=0.05)\n",
      "xgb = XGBClassifier(n_estimators=100, max_depth=6, learning_rate=0.2)\n",
      "model_list = ['RandomForest','AdaBoost','GBDT','XGboost','lightGBM']\n",
      "for index, model in enumerate([rf, ada, gbdt, xgb, lgb]):\n",
      "    a = time.time()\n",
      "    model.fit(x_train, y_train)\n",
      "    train_acc = model.score(x_train, y_train)\n",
      "    test_acc = model.score(x_test, y_test)\n",
      "    b = time.time()\n",
      "    print (\"{} train/test acc. is: {}/{}\".format(model_list[index], train_acc, test_acc))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "RandomForest train/test acc. is: 0.9550561797752809/0.8888888888888888\n",
        "AdaBoost train/test acc. is: 0.8314606741573034/0.8444444444444444"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "GBDT train/test acc. is: 0.8963795255930087/0.8222222222222222"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "XGboost train/test acc. is: 0.951310861423221/0.8333333333333334"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "lightGBM train/test acc. is: 0.9725343320848939/0.8333333333333334"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n"
       ]
      }
     ],
     "prompt_number": 95
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "rf.fit(x,y)\n",
      "rf_train_acc = rf.score(x, y)\n",
      "print (rf_train_acc)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "0.973063973064\n"
       ]
      }
     ],
     "prompt_number": 96
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data = pd.read_csv('test.csv')\n",
      "test_data.head()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>PassengerId</th>\n",
        "      <th>Pclass</th>\n",
        "      <th>Name</th>\n",
        "      <th>Sex</th>\n",
        "      <th>Age</th>\n",
        "      <th>SibSp</th>\n",
        "      <th>Parch</th>\n",
        "      <th>Ticket</th>\n",
        "      <th>Fare</th>\n",
        "      <th>Cabin</th>\n",
        "      <th>Embarked</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>892</td>\n",
        "      <td>3</td>\n",
        "      <td>Kelly, Mr. James</td>\n",
        "      <td>male</td>\n",
        "      <td>34.5</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>330911</td>\n",
        "      <td>7.8292</td>\n",
        "      <td>NaN</td>\n",
        "      <td>Q</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>893</td>\n",
        "      <td>3</td>\n",
        "      <td>Wilkes, Mrs. James (Ellen Needs)</td>\n",
        "      <td>female</td>\n",
        "      <td>47.0</td>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>363272</td>\n",
        "      <td>7.0000</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td>894</td>\n",
        "      <td>2</td>\n",
        "      <td>Myles, Mr. Thomas Francis</td>\n",
        "      <td>male</td>\n",
        "      <td>62.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>240276</td>\n",
        "      <td>9.6875</td>\n",
        "      <td>NaN</td>\n",
        "      <td>Q</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td>895</td>\n",
        "      <td>3</td>\n",
        "      <td>Wirz, Mr. Albert</td>\n",
        "      <td>male</td>\n",
        "      <td>27.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>315154</td>\n",
        "      <td>8.6625</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td>896</td>\n",
        "      <td>3</td>\n",
        "      <td>Hirvonen, Mrs. Alexander (Helga E Lindqvist)</td>\n",
        "      <td>female</td>\n",
        "      <td>22.0</td>\n",
        "      <td>1</td>\n",
        "      <td>1</td>\n",
        "      <td>3101298</td>\n",
        "      <td>12.2875</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 99,
       "text": [
        "   PassengerId  Pclass                                          Name     Sex  \\\n",
        "0          892       3                              Kelly, Mr. James    male   \n",
        "1          893       3              Wilkes, Mrs. James (Ellen Needs)  female   \n",
        "2          894       2                     Myles, Mr. Thomas Francis    male   \n",
        "3          895       3                              Wirz, Mr. Albert    male   \n",
        "4          896       3  Hirvonen, Mrs. Alexander (Helga E Lindqvist)  female   \n",
        "\n",
        "    Age  SibSp  Parch   Ticket     Fare Cabin Embarked  \n",
        "0  34.5      0      0   330911   7.8292   NaN        Q  \n",
        "1  47.0      1      0   363272   7.0000   NaN        S  \n",
        "2  62.0      0      0   240276   9.6875   NaN        Q  \n",
        "3  27.0      0      0   315154   8.6625   NaN        S  \n",
        "4  22.0      1      1  3101298  12.2875   NaN        S  "
       ]
      }
     ],
     "prompt_number": 99
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.loc[test_data['Sex']=='male','Sex']=1\n",
      "test_data.loc[test_data['Sex']=='female','Sex']=0"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 100
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.head()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>PassengerId</th>\n",
        "      <th>Pclass</th>\n",
        "      <th>Name</th>\n",
        "      <th>Sex</th>\n",
        "      <th>Age</th>\n",
        "      <th>SibSp</th>\n",
        "      <th>Parch</th>\n",
        "      <th>Ticket</th>\n",
        "      <th>Fare</th>\n",
        "      <th>Cabin</th>\n",
        "      <th>Embarked</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>892</td>\n",
        "      <td>3</td>\n",
        "      <td>Kelly, Mr. James</td>\n",
        "      <td>1</td>\n",
        "      <td>34.5</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>330911</td>\n",
        "      <td>7.8292</td>\n",
        "      <td>NaN</td>\n",
        "      <td>Q</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>893</td>\n",
        "      <td>3</td>\n",
        "      <td>Wilkes, Mrs. James (Ellen Needs)</td>\n",
        "      <td>0</td>\n",
        "      <td>47.0</td>\n",
        "      <td>1</td>\n",
        "      <td>0</td>\n",
        "      <td>363272</td>\n",
        "      <td>7.0000</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td>894</td>\n",
        "      <td>2</td>\n",
        "      <td>Myles, Mr. Thomas Francis</td>\n",
        "      <td>1</td>\n",
        "      <td>62.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>240276</td>\n",
        "      <td>9.6875</td>\n",
        "      <td>NaN</td>\n",
        "      <td>Q</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td>895</td>\n",
        "      <td>3</td>\n",
        "      <td>Wirz, Mr. Albert</td>\n",
        "      <td>1</td>\n",
        "      <td>27.0</td>\n",
        "      <td>0</td>\n",
        "      <td>0</td>\n",
        "      <td>315154</td>\n",
        "      <td>8.6625</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td>896</td>\n",
        "      <td>3</td>\n",
        "      <td>Hirvonen, Mrs. Alexander (Helga E Lindqvist)</td>\n",
        "      <td>0</td>\n",
        "      <td>22.0</td>\n",
        "      <td>1</td>\n",
        "      <td>1</td>\n",
        "      <td>3101298</td>\n",
        "      <td>12.2875</td>\n",
        "      <td>NaN</td>\n",
        "      <td>S</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 101,
       "text": [
        "   PassengerId  Pclass                                          Name  Sex  \\\n",
        "0          892       3                              Kelly, Mr. James    1   \n",
        "1          893       3              Wilkes, Mrs. James (Ellen Needs)    0   \n",
        "2          894       2                     Myles, Mr. Thomas Francis    1   \n",
        "3          895       3                              Wirz, Mr. Albert    1   \n",
        "4          896       3  Hirvonen, Mrs. Alexander (Helga E Lindqvist)    0   \n",
        "\n",
        "    Age  SibSp  Parch   Ticket     Fare Cabin Embarked  \n",
        "0  34.5      0      0   330911   7.8292   NaN        Q  \n",
        "1  47.0      1      0   363272   7.0000   NaN        S  \n",
        "2  62.0      0      0   240276   9.6875   NaN        Q  \n",
        "3  27.0      0      0   315154   8.6625   NaN        S  \n",
        "4  22.0      1      1  3101298  12.2875   NaN        S  "
       ]
      }
     ],
     "prompt_number": 101
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data['Age'].mean()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 104,
       "text": [
        "30.272590361445783"
       ]
      }
     ],
     "prompt_number": 104
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.loc[test_data['Age'].isnull(), 'Age']=30.272590"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 105
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.isnull().sum()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 106,
       "text": [
        "PassengerId      0\n",
        "Pclass           0\n",
        "Name             0\n",
        "Sex              0\n",
        "Age              0\n",
        "SibSp            0\n",
        "Parch            0\n",
        "Ticket           0\n",
        "Fare             1\n",
        "Cabin          327\n",
        "Embarked         0\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 106
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data['Fare'].mean()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 107,
       "text": [
        "35.627188489208635"
       ]
      }
     ],
     "prompt_number": 107
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.loc[test_data['Fare'].isnull(), 'Fare']=35.627188"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 108
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_data.isnull().sum()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 109,
       "text": [
        "PassengerId      0\n",
        "Pclass           0\n",
        "Name             0\n",
        "Sex              0\n",
        "Age              0\n",
        "SibSp            0\n",
        "Parch            0\n",
        "Ticket           0\n",
        "Fare             0\n",
        "Cabin          327\n",
        "Embarked         0\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 109
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x = []\n",
      "index = []\n",
      "len1 = test_data.shape[0]\n",
      "for i in range(len1):\n",
      "    test_sample = test_data.iloc[i, [1,3,4,5,6,8]]\n",
      "    x.append(np.array(test_sample))\n",
      "    index.append(test_data.iat[i, 0])\n",
      "x = np.array(x)\n",
      "index = np.array(index)\n",
      "print (x)\n",
      "print (index)\n",
      "print (len(x))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[[3 1 34.5 0 0 7.8292000000000002]\n",
        " [3 0 47.0 1 0 7.0]\n",
        " [2 1 62.0 0 0 9.6875]\n",
        " ..., \n",
        " [3 1 38.5 0 0 7.25]\n",
        " [3 1 30.272590000000001 0 0 8.0500000000000007]\n",
        " [3 1 30.272590000000001 1 1 22.3583]]\n",
        "[ 892  893  894  895  896  897  898  899  900  901  902  903  904  905  906\n",
        "  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921\n",
        "  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936\n",
        "  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951\n",
        "  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966\n",
        "  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981\n",
        "  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996\n",
        "  997  998  999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011\n",
        " 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026\n",
        " 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041\n",
        " 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056\n",
        " 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071\n",
        " 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086\n",
        " 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101\n",
        " 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116\n",
        " 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131\n",
        " 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146\n",
        " 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161\n",
        " 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176\n",
        " 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191\n",
        " 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206\n",
        " 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221\n",
        " 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236\n",
        " 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251\n",
        " 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266\n",
        " 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281\n",
        " 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296\n",
        " 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309]\n",
        "418\n"
       ]
      }
     ],
     "prompt_number": 110
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "test_result = rf.predict(x)\n",
      "test_result"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 111,
       "text": [
        "array([0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1,\n",
        "       1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0,\n",
        "       1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0,\n",
        "       1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,\n",
        "       1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,\n",
        "       0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
        "       0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,\n",
        "       1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0,\n",
        "       1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0,\n",
        "       0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0,\n",
        "       0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1,\n",
        "       0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,\n",
        "       0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,\n",
        "       0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,\n",
        "       0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,\n",
        "       1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0,\n",
        "       1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0,\n",
        "       1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0,\n",
        "       1, 0, 0, 0])"
       ]
      }
     ],
     "prompt_number": 111
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "index_s = pd.Series(index)\n",
      "result_s = pd.Series(test_result)\n",
      "df = pd.DataFrame()\n",
      "df['PassengerId'] = index_s\n",
      "df['Survived'] = result_s\n",
      "df.to_csv(\"result.csv\", index=None)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 114
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}